<?php
// Library File
include 'lib/library.php';

login_check();

$title = 'Friend Network';
$subtitle = 'Friend Network';

	$friend_query = mysql_query("	
				SELECT friend2 FROM friends WHERE type='friend' AND accepted=1 AND friend1='$m_user_id'
				UNION
				SELECT friend1 FROM friends WHERE type='friend' AND accepted=1 AND friend2='$m_user_id'
			");
	
	$friend_query_array = mysql_fetch_assoc($friend_query);
	
	$friend_query_array_size = count($friend_query_array);
	
	$friend_array;
	for($x=0;$x<$friend_query_array_size;$x++){
		if($friend_query_array['friend1']){
			$friend_array["$x"] = $friend_query_array['friend1'];
		}else if($friend_query_array['friend2']){
			$friend_array["$x"] = $friend_query_array['friend2'];
		}
	}
	
	$friend_array_size = count($friend_array);
	
	
	for($x=0;$x<$friend_array_size;$x++){
		if($x==0 && $friend_array_size > 0){
			$content .= '<h2>Friends</h2>';
		}
		$friend_info_query = mysql_query("SELECT name FROM users WHERE user_id='{$friend_array["$x"]}'");
		$friend_info_array = mysql_fetch_assoc($friend_info_query);
		$content .= '<P><a href="'.$addr.'/profile.php?id='.$friend_array["$x"].'">'.$friend_info_array['name'].'</a></P>';
	}
		
	$temp_contanct_query = mysql_query("SELECT friend2 FROM friends WHERE type='contact' AND friend1='$m_user_id'");
	
	$displayed = false;
	while($temp_contact_array = mysql_fetch_assoc($temp_contanct_query)){
		if(!$displayed){
			$content .= '<h2>Temporary Contacts</h2>';
			$displayed = true;
		}
		
		$temp_contact_info_query = mysql_query("SELECT name FROM users WHERE user_id='{$temp_contact_array['friend2']}'");
		
		$temp_contact_info_array = mysql_fetch_assoc($temp_contact_info_query);
		$content .= '<P><a href="'.$addr.'/messages.php?mode=compose&to='.$temp_contact_info_array['name'].'">'.$temp_contact_info_array['name'].'</a></P>';
	}

$content ;

/*
**   P U T    V A R S
**    O N    P A G E
*/
	head($title,$style,$scripts);
	body($header,$personal,$subtitle,$content,$navigation);
	foot($footer,$dbc);
?> 
